#!/usr/bin/python
#coding=utf-8

# 获取fil每日产出量
import requests
import bs4

from predis import QueryRedis
redis = QueryRedis()

url = "https://filfox.info/en"
# 获取官网内容
html = requests.get(url)
# 解释官网
soup = bs4.BeautifulSoup(html.text, 'html.parser')
# 匹配数据
results = soup.find_all('div', "text-left lg:text-center text-sm lg:text-2xl items-start lg:mx-auto")
# 处理数据
for item in results:
    curr_line = item.string
    if "FIL/T" in curr_line:
        curr_line = curr_line.replace('FIL/TiB', '', 1)
        if curr_line:
            curr_line = float(curr_line)
        else:
            continue
        if curr_line < 1:
            # 保存到缓存
            key = "curr_output_fil"
            redis.set(key, curr_line, 86400)
            print(curr_line)